home *** CD-ROM | disk | FTP | other *** search
/ Network Supervisor's Toolkit / Network Supervisor's Toolkit.iso / tools / nwtp06 / qavail.pas < prev    next >
Pascal/Delphi Source File  |  1996-07-10  |  3KB  |  96 lines

  1. program QAvailable;
  2.  
  3. { QMS related utility / NwTP 0.5 API. (c) 1993,1994, R.Spronk }
  4.  
  5. uses nwMisc,nwBindry,nwQMS;
  6.  
  7. Var Qname :string;
  8.     QobjId:Longint;
  9.     Qtype :word;
  10.  
  11.     BinAccLev:Byte;
  12.     MyObjId  :Longint;
  13.     MyObjName:string;
  14.     MyObjType:word;
  15.  
  16.     SegNbr   :Byte;
  17.     propName :string;
  18.     propValue:Tproperty;
  19.     moreSeg  :boolean;
  20.     propFlags:byte;
  21.     i        :Byte;
  22.  
  23.     GrpObjId  :Longint;
  24.     GrpObjName:string;
  25.     GrpObjType:word;
  26.  
  27. begin
  28. {--- Parameter section }
  29.  
  30. if paramCount<>1
  31.  then begin
  32.       writeln('QAVAIL usage:  QAVAIL <queue name>');
  33.       writeln('Batch file utility to check for the availability of queues.');
  34.       writeln;
  35.       writeln('Errorlevel 0 : Queue exists, calling user is allowed to use Queue');
  36.       writeln('           1 : Queue doesn''t exist on default fileserver.');
  37.       writeln('           2 : Queue exists but calling user has no Queue rights.');
  38.       halt(1); { No queue available }
  39.       end;
  40. Qname:=ParamStr(1);
  41.  
  42. {--- Startup checks }
  43.  
  44. IF Not (IsShellLoaded and IsUserLoggedOn)
  45.  then halt(1); { Queue not available }
  46.  
  47. {--- Queue name in bindery of effective server ? }
  48.  
  49. UpString(Qname);
  50. IF not GetBinderyObjectId(Qname,3 {ot_print_queue},QobjId)
  51.  then halt(1);
  52.  
  53. {--- Queue exists. Does the caller have rights to use the queue ? }
  54.  
  55. IF NOT (GetBinderyAccessLevel(BinAccLev,MyObjId) and
  56.         GetBinderyObjectName(MyObjId,MyObjName,MyObjType))
  57.   then halt(1); { Oops.. some kind of bindery error }
  58.  
  59. IF IsBinderyObjectInSet(Qname,3 {OT_PRINT_QUEUE},'Q_USERS',MyObjName, MyObjType)
  60.  then halt(0); { OK. Caller has rights }
  61.  
  62. if nwbindry.result=$FB { According to QMS definitions, when the property }
  63.  then halt(0);         { Q_USERS doesn't exist, all users have queue rights. }
  64.  
  65. {--- Is one of the groups I'm a member of a queue user ? }
  66.  
  67. SegNbr:=1;
  68. propName:='GROUPS_I''M_IN';
  69.  
  70. While ReadPropertyValue(MyObjName,MyObjType,propName,SegNbr,
  71.                         propValue,moreSeg,propFlags)
  72.  do begin
  73.     { A segment of a set-property consists of a list of object IDs,
  74.       each ID 4 bytes long, stored hi-lo.
  75.       The end of the list (within THIS segment) is marked by an ID of 00000000. }
  76.     i:=1;
  77.     Repeat
  78.      GrpObjId:=MakeLong((propValue[i] *256 +propValue[i+1]), ( propValue[i+2] *256 + propValue[i+3] ) );
  79.      if GrpObjId<>0
  80.       then begin
  81.            IF GetBinderyObjectName(GrpObjId,GrpObjName,GrpObjType)
  82.               and IsBinderyObjectInSet(Qname,3 {OT_PRINT_QUEUE},
  83.                                        'Q_USERS',GrpObjName, GrpObjType)
  84.             then halt(0); { OK. Caller's group has queue rights }
  85.            end;
  86.      inc(i,4);
  87.     Until (i>128) or (GrpObjId=0);
  88.     inc(SegNbr);
  89.     end;
  90.  
  91. {--- Still no rights found.. }
  92. halt(2);
  93.  
  94. end.
  95.  
  96.